﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApi.Core.IRepository;
using WebApi.Core.Model;
using WebApi.Core.Repository.Base;
using WebApi.Core.Repository.SqlSugar;

namespace WebApi.Core.Repository
{
    public class RoleRepository : BaseRepository<Roles>, IRoleRepository
    {  
        public RoleRepository(ILogger<BaseRepository<Roles>> logger) :base(logger)
        { 

        }

        public async Task<List<Roles>> GetRolesByUserIdAsync(string userId)
        {
            return await _db.Queryable<UserRoles>()
                .InnerJoin<Roles>((ur,r) => ur.RoleId == r.Id.ToString())
                .Where(ur => ur.UserId == userId)
                .Select<Roles>()
                .ToListAsync(); 
        }
    }
}
